package com.fay.designPattern.principles.solid;
/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/3/1 17:41
 * @Version 1.0
 */
public class AlertAppContext {
    private AlertRule alertRule;
    private Notification notification;
    private Alert2 alert;

    public void initializeBeans() {
        alertRule = new AlertRule();
        notification = new Notification();
        alert = new Alert2();
        alert.addAlertHandler(new TpsAlertHandler(alertRule, notification));
        alert.addAlertHandler(new ErrorAlertHandler(alertRule, notification));
    }

    public Alert2 getAlert() {
        return alert;
    }

    // 饿汉单例
    private static final AlertAppContext instance = new AlertAppContext();

    private AlertAppContext() {
        instance.initializeBeans();
    }

    public static AlertAppContext getInstance() {
        return instance;
    }

    public static void main(String[] args) {
        ApiStatInfo apiStatInfo = new ApiStatInfo();
        //... 省略配置apiStatInfo数据值代码
        AlertAppContext.getInstance().getAlert().check(apiStatInfo);
    }
}
